package util

import (
	"github.com/astaxie/beego/logs"
	"gopkg.in/yaml.v2"
	"io/ioutil"
)

// ParseYaml Parse yaml
func ParseYaml(filePath string) (map[string]map[string]string, error) {
	file, err := ioutil.ReadFile(filePath)
	if err != nil {
		logs.Error("ioutil.ReadFile error:", filePath, err.Error())
		return nil, err
	}

	resultMap := make(map[string]map[string]string)
	err = yaml.Unmarshal(file, resultMap)
	if err != nil {
		logs.Error("yaml.Unmarshal error:", err)
		return nil, err
	}

	return resultMap, nil
}

func ParseYamlTypeTwo(filePath string) (map[string]map[string]map[string]string, error) {
	file, err := ioutil.ReadFile(filePath)
	if err != nil {
		logs.Error("ioutil.ReadFile error:", filePath, err.Error())
		return nil, err
	}
	resultMap := make(map[string]map[string]map[string]string)

	err = yaml.Unmarshal(file, resultMap)
	if err != nil {
		logs.Error("yaml.Unmarshal error:", err)
		return nil, err
	}
	return resultMap, nil

}
